<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*"%>
<%@ page import="cleanstarxchange.server.*"%>
<%@ page import="javax.jdo.PersistenceManager"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>    
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="java.text.DecimalFormat"%>
    
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
	<%		Integer uid = Integer.parseInt( request.getParameter( "uid" ) );
 %>
	
	
	<script language="javascript">
	<!--
	function moveToHome()
	{
   		var frm = document.frm;
	   	frm.action = "index.jsp?uid=<%=uid%>";
   		frm.submit();
	}

	function moveToPF()
	{
   		var frm = document.frm;
	   	frm.action = "portfolio.jsp?uid=<%=uid%>";
   		frm.submit();
	}
	function moveToUpdate()
	{
   		var frm = document.frm;
	   	frm.action = "update.jsp?uid=<%=uid%>&updateid=1";
   		frm.submit();
	}
	//-->
	</script>
	
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Star XChange</title>
		<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
		
		<!--[if IE]>
		<style type="text/css"> 
		/* place css fixes for all versions of IE in this conditional comment */
		.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
		.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
		/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
		</style>
		<![endif]-->
	</head>

	<body class="twoColElsLtHdr">
	<%
	
		DataStore ds = new DataStore();
		if (!ds.isInitialized()){
			Initializer.Initialize();		
			//ds.initialize();
		}			

		
		//Getting from DS part: this looks siliy it gotta be here until we fix some problem with ptr
		ArrayList<Stock> stocks = new ArrayList<Stock>();
        ArrayList<Stock> stks = ds.getStockSQL();
        
		for ( int i = 0; i < stks.size(); i++ ){
       		stocks.add(stks.get(i));
		}
        	
        //ArrayList<Stock> stocks = ds.getStock();
		//List<Stock> sl = ds.getStockSQL();
		int size = stocks.size();
		//int size2 = sl.size();
    %>
	<div id="container">
  		
  		<div id="header"><a href="index.jsp?uid=<%=uid%>"><img src="media/logo.jpg"/></a>
  		<!-- end #header -->
  		</div>
  		
  		<div id="sidebar1">
   			<ul class="sidenav">
				<li>
                	<a href="portfolio.jsp?uid=<%=uid%>" title="My Portfolio">My Portfolio
                    <span>See how rich I am</span>
                    </a>
                    
                </li>
			    <li>
                	<a href="stocklist.jsp?uid=<%=uid%>" title="Stocks">Stocks
                    <span>See the market flow</span>
                    </a>
                </li>
				<li>
                	<a href="rank.jsp?uid=<%=uid%>" title="Rank">Rank
                    <span>Who is the winner now</span>
                    </a>
                </li>
				<li>
                	<a href="howtoplay.jsp?uid=<%=uid%>" title="HowToPlay">How To Play
                    <span>Learn how to play the game</span>
                    </a>
                </li>
			</ul>
    	<!-- end #sidebar1 -->
    	</div>
  		
  		<div id="mainContent">
    		<div id="shortcut">
    			<form name="frm" method="post">
				<input type="button" name="btregister" value = "Home" onClick="moveToHome();">
				<input type="button" name="btregister" value = "Portfolio" onClick="moveToPF();">
				<% if ( uid==713865194 || uid==21014218 || uid==783920693 || uid==514766462 ){ %>
				<input type="button" name="btregister" value = "Update Now" onClick="moveToUpdate();">
				<%} %>
				</form>
    		</div>
    		<div id="shortcut">
    			<table width="95%" border="0" cellspacing="2" cellpadding="2">
  					<tr>
    					<th scope="col">Trade</th>
    					<th scope="col">Celeb Name</th>
    					<th scope="col">Price</th>
    					<th scope="col">High</th>
    					<th scope="col">Low</th>
    					<th scope="col"><div align="center">U/D</div></th>
  					</tr>
  					<% for( int i=0; i<size; i++ ){ %>
  					<tr>
  					<%      
  							String color;
  							double delta = stocks.get(i).getCurrentPrice() - stocks.get(i).getPreviousPrice(1);
  							boolean changed = false;
  							char cha;
  							String sign;
  							
  	  						DecimalFormat twoDForm = new DecimalFormat("#.##");
  	  						delta = Double.valueOf(twoDForm.format(delta));
  	  						
 							if( stocks.get(i).getCurrentPrice() > stocks.get(i).getPreviousPrice(1) ){
    							color = "#00ff00";
    							cha='U';
    							sign="+";
    						}
    						else if( stocks.get(i).getCurrentPrice() < stocks.get(i).getPreviousPrice(1) ){
    							color = "#ff0000";
    							cha='D';
    							sign="";
    						}
    						else{
    							color = "#000000";
    							cha='-';
    							sign="";
    						}
    				%>
    			
    					<td><a href="stockprofile.jsp?uid=<%=uid %>&stockid=<%=stocks.get(i).getStockID()%>"> <img src="media/trade.jpg"/></a></td>
   						<td><%=stocks.get(i).getName() %></td>
   						<td><%=stocks.get(i).getCurrentPrice() %>  <% if(delta!=0){%>(<span style="color:<%=color%>"><%=sign%><%=delta%></span>)<% } %></td>
    					<td><%=stocks.get(i).getHighPrice() %></td>
    					<td><%=stocks.get(i).getLowPrice() %></td>
    					<td><div align="center"><span style="color:<%=color%>"><%=String.valueOf(cha) %></span></div></td>
  					</tr>
  					
  					<% } %>
  				</table>
    		</div>
    		<!-- end #mainContent -->
    	</div>
		
		<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
		<br class="clearfloat" />
   		
   		<div id="footer">
    		<p><%=ds.toString() %>
    			
    		</p>
  		<!-- end #footer -->
  		</div>
  		
	<!-- end #container -->
	</div>
	<% ds.close();
	%>
	
	</body>
</html>
